<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../assets/css/base.css">
</head>
<body>
    <div id="app">
        <p>tempMsg:{{ tempMsg }}</p>
        <comp-a @update:msg=" updateMsg "></comp-a>
        <comp-b :msg=" tempMsg "></comp-b>
    </div>

    <!-- 组件A-A -->
    <script type="text/x-template" id="compAa">
        <div class="cbox">
            <h5>组件A-A</h5>
            <p>msg：{{ msg }}</p>
            <input type="button" value="发送msg数据" @click=" $emit('update:msg',msg) ">
        </div>
    </script>
    <!-- 组件A -->
    <script type="text/x-template" id="compA">
        <div class="cbox">
            <h5>组件A</h5>
            <comp-aa @update:msg=" updateMsg "></comp-aa>
        </div>
    </script>

    <!-- 组件B-A -->
    <script type="text/x-template" id="compBa">
        <div class="cbox">
            <h5>组件B-A</h5>
            <p>msg:{{ msg }}</p>
        </div>
    </script>
    <!-- 组件B -->
    <script type="text/x-template" id="compB">
        <div class="cbox">
            <h5>组件B</h5>
            <comp-ba :msg=" msg "></comp-ba>
        </div>
    </script>
   

    <script type="module">
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";
        const CompAa = {
            template:"#compAa",
            emits:["update:msg"],
            data() {
                return {
                    msg: "组件a-a的数据变量 msg"
                }
            },
        }
        const CompBa = {
            template:"#compBa",
            props:["msg"]
        }
        const CompA = {
            template:"#compA",
            emits:["update:msg"],
            components: {
                CompAa,
            },
            methods: {
                updateMsg(e) {
                    console.log("组件A",e)
                    this.$emit("update:msg",e)
                }
            },
        }
        const CompB = {
            template:"#compB",
            props:["msg"],
            components: {
                CompBa,
            },
        }
        createApp({
            components: {
                CompA,CompB
            },
            data() {
                return {
                    tempMsg:""
                }
            },
            methods: {
                updateMsg(e) {
                    console.log("根组件",e)
                    this.tempMsg = e;
                }
            },
        }).mount("#app")
    </script>
</body>
</html>